//
//  PacketUtility.m
//  QBIM
//
//  Created by liu nian on 14-3-19.
//  Copyright (c) 2014年 liunian. All rights reserved.
//

#import "PacketUtility.h"

@implementation PacketUtility
+ (int)getPacketSeqID{
    static int base_seq = 1;
    base_seq = (base_seq + 1) % 4294967296;
    return base_seq;
}

//unsigned 4bytes
+(uint32_t) NSDataToUInt:(NSData *)data
{
    unsigned char bytes[4];
    [data getBytes:bytes length:4];
    uint32_t n = (int)bytes[0] << 24;
    n |= (int)bytes[1] << 16;
    n |= (int)bytes[2] << 8;
    n |= (int)bytes[3];
    return n;
}

//unsigned 4bytes
+(uint32_t) NSDataToInt:(NSData *)data
{
    char buff;
    [data getBytes:&buff length:1];
    int i = buff;
    return i;
}

+ (NSDate *)dateFromString:(NSString *)dateString{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat: @"yyyy-MM-dd HH:mm:ss"];
    NSDate *destDate= [dateFormatter dateFromString:dateString];
    return destDate;

}

+ (NSString *)stringFromDate:(NSDate *)date{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //zzz表示时区，zzz可以删除，这样返回的日期字符将不包含时区信息 +0000。
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *destDateString = [dateFormatter stringFromDate:date];
    return destDateString;
    
}
@end
